package com.testDemo.hutool;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import org.junit.jupiter.api.Test;

/**
 * @author : zouren
 * @date : 2020/3/26 14:15
 */
public class JSONPathByFastjsonTest {
    @Test
    public void testSetV(){
        JSONObject root = new JSONObject();
        JSONPath.set(root,"$.clientRightItem.ocId","权益责任ID");
        JSONPath.set(root,"$.applier.name","name");
        JSONPath.set(root,"$.applier.certType","certType");
        JSONPath.set(root,"$.applier.certNo","certNo");
        JSONPath.set(root,"$.applier.phoneNo","phoneNo");
        JSONPath.set(root,"$.applier.name","name1");
        JSONPath.set(root,"$.applier.certType","certType1");
        JSONPath.set(root,"$.applier.certNo","certNo1");
        JSONPath.set(root,"$.applier.phoneNo","phoneNo1");

        System.out.println(root);
    }
    @Test
    public void testSetV1(){
        JSONArray root = new JSONArray();
        JSONObject row = new JSONObject();
        row.put("a","a1");
        root.add(row);
        JSONObject row1 = new JSONObject();
        row1.put("a","a2");
        root.add(row1);
        Object  o= JSONPath.eval(root,"$");
        System.out.println(o);
//        JSONPath.set(root,"$.clientRightItem.ocId","权益责任ID");

    }
    @Test
    public void testSetV2(){
        cn.hutool.json.JSONArray root = new cn.hutool.json.JSONArray();
        cn.hutool.json.JSONObject row = new cn.hutool.json.JSONObject();
        row.put("a","a1");
        root.add(row);
        cn.hutool.json.JSONObject row1 = new cn.hutool.json.JSONObject();
        row1.put("a","a2");
        root.add(row1);
        Object byPath = JSONUtil.getByPath(root, "$..a");

        System.out.println(byPath);

    }
    public void test1(){
        String json="  {btn: {\n" +
                "    sp0Res: {\n" +
                "      sp0Res001001: '保存',\n" +
                "      // 优惠卷兑换\n" +
                "      sp0Res003001: 'Search',\n" +
                "      sp0Res003002: 'Reset',\n" +
                "      sp0Res003003: 'Edit',\n" +
                "      sp0Res003004: 'View',\n" +
                "      sp0Res003005: 'Collect',\n" +
                "      sp0Res003005001: 'Confirm',\n" +
                "      sp0Res003005003: 'Cancel',\n" +
                "      sp0Res003005002: 'Upload',\n" +
                "      sp0Res003006: '+ New Appointment',\n" +
                "      sp0Res003007: 'Cancel',\n" +
                "      sp0Res003008: 'Create Appointment',\n" +
                "      sp0Res003007001: 'Confirm',\n" +
                "      sp0Res003007002: 'Cancel',\n" +
                "      sp0Res003007003: 'Upload'\n" +
                "    }\n" +
                "  }}";
        cn.hutool.json.JSONObject object = JSONUtil.parseObj(json);
    }

}
